//
//  JZChangePassWordViewController.m
//  QuanZiChat
//
//  Created by lanou3g on 15/11/21.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "JZChangePassWordViewController.h"

@interface JZChangePassWordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *oldPassWord;
@property (weak, nonatomic) IBOutlet UITextField *passWord1;
@property (weak, nonatomic) IBOutlet UITextField *passWord2;



@end

@implementation JZChangePassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.userName resignFirstResponder];
    [self.oldPassWord resignFirstResponder];
    [self.passWord1 resignFirstResponder];
    [self.passWord2 resignFirstResponder];
}

- (IBAction)confirmChangePassWord:(id)sender {
    [AVUser logInWithUsernameInBackground:self.userName.text password:self.oldPassWord.text block:^(AVUser *user, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        }
        
    }];
    //请确保用户当前的有效登录状态
    [[AVUser currentUser] updatePassword:self.oldPassWord.text newPassword:self.passWord1.text block:^(id object, NSError *error) {
        //处理结果
        if (!error) {
            NSLog(@"修改成功");
            
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            NSLog(@"修改失败%@", error);
        }
    }];
}

//取消更改密码
- (IBAction)cancleChangePassword:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
